<%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="java.net.URLEncoder"%>
<%@page import="java.io.OutputStream"%>
<%@page import="java.io.FileInputStream"%>
<%@page import="java.io.File"%>
<%
	  String path = request.getContextPath();
	  String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
	  //以下两句代码防止重复调用输出流
	  out.clear();
      out = pageContext.pushBody();
      //==================================
      response.reset();//清理上次下载痕迹
      String  filePath = "";//初始文件名称参数
      String  filePathAddr = "";//初始化路径参数
      response.setContentType("application/x-download");
      filePath = request.getParameter("filePathAddr");//获取文件下载参数
      filePath = new String(filePath.getBytes("ISO8859-1"),"UTF-8");
      filePathAddr = request.getSession().getServletContext().getRealPath("/soft") + "/" + filePath;
      String filedisplay = filePathAddr.substring(filePathAddr.lastIndexOf("/")+1,filePathAddr.length());
      filedisplay = URLEncoder.encode(filedisplay,"UTF-8");
      response.addHeader("Content-Disposition","attachment;filename=" + filedisplay);
      OutputStream outp = null;
      FileInputStream in = null;
      try{
          outp = response.getOutputStream();
          File file = new File(filePathAddr);
          in = new FileInputStream(file);
          byte[] b = new byte[4096];
          int i = 0;
          while((i = in.read(b)) > 0){
              outp.write(b, 0, i);
          }
          outp.flush();
      }catch(Exception e){
          System.out.println("下载异常操作");
      }
      finally{
          if(in != null){
              in.close();
              in = null;
          }
          if(outp != null){
              outp.close();
              outp = null;
          }
      }
%>
